<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Category_model extends MY_Model
{
	function Category_model()
	{
		parent::MY_Model();
		$this->load->helper('date');
	}
	
	function get_all($start, $numItem)
	{
		$data = array();
		$data['lstCategory'] = array();
		$result = $this->getRowsOnMultiQuery("CALL nm_admin_category_getall('$start', '$numItem');");
        $data['lstCategory'] = $result[0];
		$data['iCount'] = 0;
		$data['iCount'] = (int)$result[1][0]['num'];
		$data['pCount'] = ($data['iCount'] > $numItem) ? ceil($data['iCount']/$numItem) : 1;
		return $data;
	}
	
	function add($catname, $categorydir, $listorder, $status, $installtime)
	{
		$uidAction = (int)$this->session->userdata('uid');
		$this->exeQuery("CALL nm_admin_category_insert('$catname','$categorydir','$listorder','$status','$installtime',$uidAction)");
	}
	
	function update($category_id, $catname, $categorydir, $listorder)
	{
		$ci = & get_instance();
		$uidAction = (int)$ci->session->userdata('uid');
		$this->exeQuery("CALL nm_admin_category_update('$category_id','$catname','$categorydir','$listorder',$uidAction)");
	}
	
	function delete($category_id)
	{
		$ci = & get_instance();
		$uidAction = (int)$ci->session->userdata('uid');
		$this->exeQuery("CALL nm_admin_category_delete('$category_id','$uidAction')");
	}
	
	function active($category_id,$status)
	{
		$ci = & get_instance();
		$uidAction = (int)$ci->session->userdata('uid');
		$this->exeQuery("CALL nm_admin_category_active('$category_id','$status','$uidAction')");
	}
	
	function check_catname_available($catname,$catid=0)
	{
		$row = $this->getRows("CALL nm_category_check_catname_available('$catname','$catid');", 0);
		$chk = false;
		if($row[0] == 0)
		{
			$chk = true;
		}
		return $chk;
	}
	
	function check_categorydir_available($categorydir,$catid=0)
	{
		$row = $this->getRows("CALL nm_category_check_categorydir_available('$categorydir','$catid');", 0);
		$chk = false;
		if($row[0] == 0)
		{
			$chk = true;
		}
		return $chk;
	}
	
	function get_category_info($catid)
	{
		return $this->getRows("CALL nm_get_category_info('$catid');", 0);
	}
	    
}